<?php
/**
 * Smarty plugin
 * @category VaselinEngine
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {form}{/form} block plugin
 *
 * Type:     block function<br>
 * Name:     form<br>
 * Purpose:  Creates form with generated JS for client side form validation
 *
 * @author Konstantin Shamko <konstantin.shamko@gmail.com>
 * @param array params - form attributes (see html tag <form> spec)
 * @param string contents of the block
 * @param Smarty clever simulation of a method
 * @return void
 */
function smarty_block_form($params, $content, &$smarty)
{
	//include_once("libs/validator/validator.class.php");
	$oValid=new Bel_Forms_Validator();//validator();

	if (!isset($params['name'])) {
		$smarty->trigger_error("form: missing 'name' parameter");
		return;
	}

	if(isset($content))
	{
		echo "<form id='".$params['name']."' ";
		foreach($params as $_key => $_val) {
			if($_key=='method'){
				echo $_key."='".strtolower($_val)."' ";
			}else{
				echo $_key."='".$_val."' ";	
			}			
		}	
		echo '>';
		echo $content;			
		
		echo "</form>";		

		
		
		echo "<script type='text/javascript'>";
		echo "$(document).ready(function() {";
		$oValid->generateValidateJS($params['name']);
		echo "})";
		echo "</script>";	
	}
}